package com.phospherus.common.controller.handler;

import java.util.Collection;

/**
 * @author songjinlong
 * @version 1.0
 * @since 2017/04/18
 */
public class ResultHandler<T> {
    private int code;
    private Data<T> data;
    private String message;

    public ResultHandler() {
    }

    public ResultHandler(SystemMessage systemMessage, Data<T> data) {
        this.code = systemMessage.code;
        this.message = systemMessage.message;
        this.data = data;
    }

    public ResultHandler(SystemMessage systemMessage, Collection<T> list) {
        this.code = systemMessage.code;
        this.message = systemMessage.message;
        this.data = new Data<>().add(list);
    }

    public ResultHandler(SystemMessage systemMessage, T t) {
        this.code = systemMessage.code;
        this.message = systemMessage.message;
        this.data = new Data<>().add(t);
    }

    public ResultHandler(SystemMessage systemMessage) {
        this.code = systemMessage.code;
        this.message = systemMessage.message;
    }

    public ResultHandler(int code, Data<T> data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public ResultHandler(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultHandler(int code, String message, T t) {
        this.code = code;
        this.message = message;
        this.data = new Data<>().add(t);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Data<T> getData() {
        return data;
    }

    public void setData(Data<T> data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public enum SystemMessage {
        SYSTEM_ERROR(-1, "系统内部错误！"),
        SUCCESS(1, "执行成功"),
        FAIL(0, "查询执行失败");

        int code;
        String message;

        SystemMessage(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }
}